<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>quick-cocos2d-x API Documents - framework.client.luaoc</title>
<link rel="stylesheet" href="luadocx-style.css" type="text/css" />
<link rel="stylesheet" href="luadocx-style-monokai.css" type="text/css" />
<script src="luadocx-highlight.min.js"></script>
<script type="text/javascript" charset="utf-8">hljs.initHighlightingOnLoad();</script>
</head>
<body>
  <div id="container">

    <table id="main">
      <tr>
        <td id="navigation">

          <h2>Links</h2>
          <ul>
            <li><a href="index.html">Index</a></li>
          </ul>

          <h2>Modules</h2>
          <ul>
            <li><a href="index.html">framework.init</a></li>
            <li><a href="framework.client.api.context.html">framework.client.api.Context</a></li>
            <li><a href="framework.client.api.eventprotocol.html">framework.client.api.EventProtocol</a></li>
            <li><a href="framework.client.api.gamenetwork.html">framework.client.api.GameNetwork</a></li>
            <li><a href="framework.client.api.gamestate.html">framework.client.api.GameState</a></li>
            <li><a href="framework.client.api.localize.html">framework.client.api.Localize</a></li>
            <li><a href="framework.client.api.store.html">framework.client.api.Store</a></li>
            <li><a href="framework.client.api.timer.html">framework.client.api.Timer</a></li>
            <li><a href="framework.client.api.gamenetwork.openfeint.html">framework.client.api.gamenetwork.OpenFeint</a></li>
            <li><a href="framework.client.audio.html">framework.client.audio</a></li>
            <li><a href="framework.client.crypto.html">framework.client.crypto</a></li>
            <li><a href="framework.client.device.html">framework.client.device</a></li>
            <li><a href="framework.client.display.html">framework.client.display</a></li>
            <li><a href="framework.client.init.html">framework.client.init</a></li>
            <li><a href="framework.client.luaj.html">framework.client.luaj</a></li>
            <li><strong>framework.client.luaoc</strong></li>
            <li><a href="framework.client.network.html">framework.client.network</a></li>
            <li><a href="framework.client.scheduler.html">framework.client.scheduler</a></li>
            <li><a href="framework.client.transition.html">framework.client.transition</a></li>
            <li><a href="framework.client.ui.html">framework.client.ui</a></li>
            <li><a href="framework.server.mysqleasy.html">framework.server.MysqlEasy</a></li>
            <li><a href="framework.server.rediseasy.html">framework.server.RedisEasy</a></li>
            <li><a href="framework.server.serveraction.html">framework.server.ServerAction</a></li>
            <li><a href="framework.server.serverapp.html">framework.server.ServerApp</a></li>
            <li><a href="framework.server.session.html">framework.server.Session</a></li>
            <li><a href="framework.server.init.html">framework.server.init</a></li>
            <li><a href="framework.shared.modelbase.html">framework.shared.ModelBase</a></li>
            <li><a href="framework.shared.debug.html">framework.shared.debug</a></li>
            <li><a href="framework.shared.errors.html">framework.shared.errors</a></li>
            <li><a href="framework.shared.functions.html">framework.shared.functions</a></li>
          </ul>

        </td> <!-- navigation -->

        <td id="content">

          <h1>Module <code>framework.client.luaoc</code></h1>

          <!-- BEGIN module doc -->

          <div id="module_doc">

<p>Call Objective-C form Lua, and call Lua from Objective-C.</p>

<ul>
<li>Call Objective-C Class Static Method from Lua</li>
<li>Pass aruments to Objective-C</li>
<li>Pass Lua function to Objective-C</li>
<li>Call Lua function from Objective-C</li>
</ul>

<h2>HOW TO USE:</h2>

<pre><code class="lua">local luaoc = require("framework.client.luaoc")

local function onLogin(result)
    if result == "ok" then
        print("login ok")
    else
        print("login failure, error message = ", result)
    end
end

local args = {
    username  = "dualface",
    password  = "123456",
    autologin = true,
    callback  = onLogin
}
local ok, ret = luaoc.callStaticMethod("MySDK", "login", args)
if ok then
    -- call success
    print("ret = ", ret)
else
    -- call failure
    print("error code = ", ret)
end
</code></pre>

<h3>Objective-C method:</h3>

<pre><code class="objectivec">#include "CCLuaObjcBridge.h"

+ (NSString *)login:(NSDictionary *)dict
{
    NSString *username = [dict objectForKey:@"username"];
    NSString *password = [dict objectForKey:@"password"];
    BOOL autologin = [[dict objectForKey:@"autologin"] boolValue];
    int callback = [[dict objectForKey:@"callback"] intValue];

    if (.....)
    {
        CCLuaObjcBridge::callLuaFunctionById(callback, "ok");
    }
    else
    {
        CCLuaObjcBridge::callLuaFunctionById(callback, "error message");
    }
    CCLuaObjcBridge::releaseLuaFunctionById(callback);

    return @"something";
}
</code></pre>

<br />


          </div>

          <!-- END module doc -->


          <!--  BEGIN functions index -->

          <h2>Functions</h2>
          <table class="function_list">


            <tr>
              <td class="name" nowrap><a href="#anchor_luaoc_callStaticMethod">luaoc.callStaticMethod&nbsp;(className,&nbsp;methodName,&nbsp;args)</a></td>
              <td class="summary">Call Objective-C Class Method</td>
            </tr>


          </table>

          <!--  END functions index -->

          <br />
          <br />

          <!-- BEGIN functions details -->

          <h2>Functions</h2>
          <dl class="function">


            <dt class="">
              <a name="anchor_luaoc_callStaticMethod"></a>
              <h3>luaoc.callStaticMethod (className, methodName, args)</h3>
            </dt>

            <dd class="">

<p>Call Objective-C Class Method</p>

<h3>Parameters:</h3>

<ul>
<li>string <strong>className</strong> Objective-C class name</li>
<li>string <strong>methodName</strong> Method name</li>
<li>[<em>optional table <strong>args</strong></em>] Arguments pass to Objective-C</li>
</ul>

<h3>Returns:</h3>

<ul>
<li>boolean call success or failure</li>
<li>mixed Objective-C method returned value</li>
</ul>

            </dd>


          </dl>

          <!-- BEGIN functions details -->


      </td> <!-- id="content" -->

      </tr>
    </table> <!-- id="main" -->

    <div id="about">
      <i>update: 2013-05-08 09:30:25, generated by <a href="http://github.com/dualface/luadocx">luadocx 1.1</a></i>
    </div> <!-- id="about" -->

  </div> <!-- id="container" -->

</body>
</html>
